package pcb 
{
	import com.intel.core.Application;
	import com.intel.utils.Debugger;
	import flash.display.MovieClip;
	import pcb.control.Controller;
	import pcb.control.events.LoadDataEvent;
	import pcb.models.ModelLocator;
	import pcb.views.ViewMediator;
	
	/**
	 * ...
	 * @author Fintan Boyle
	 */
	public class Main extends Application
	{

		public function Main() 
		{
			super();
			init();
		}
		
		private function init():void
		{
			//Application.PREVIEW_IN_IDE = false;
			Debugger.traceOut("APPLICATION VERSION: " + Application.VERSION);
			
			//make sure this is the document class before assigning dimensions
			if (!applicationWidth) applicationWidth = this.width;
			if (!applicationHeight) applicationHeight = this.height;
			
			initMVC();
			start();
		}
		
		private function start():void
		{
			Debugger.traceOut("Main > start()");
			var playerType:String = MovieClip(Application.root).playerType;
			//ModelLocator.getInstance().playerSettings.playerType = (playerType) ? playerType: "";
			Debugger.traceOut("Main > playerType " + playerType);
			
			//load main.swf's locale file
			//var evLoadPlayerLocale:LoadDataEvent = new LoadDataEvent(LoadDataEvent.LOAD_PLAYER_TEXT);
			//evLoadPlayerLocale.dispatch();
			
			var evSwf:LoadDataEvent = new LoadDataEvent(LoadDataEvent.LOAD_PLAYER_CONFIG);
			evSwf.data = (playerType) ? playerType: "";
			evSwf.dispatch();
		}
		
		private function initMVC():void
		{
			Debugger.traceOut("Main > initMVC()");
			var controller:Controller = new Controller();
			var models:ModelLocator = ModelLocator.getInstance();
			var view:ViewMediator = new ViewMediator();
			models.lessonStateModel.subscribeObserver(view);
			models.assetsModel.subscribeObserver(view);
			models.playerSettings.subscribeObserver(view);
			models.playerStateModel.subscribeObserver(view);
			models.mainMenuModel.subscribeObserver(view);
			models.localeModel.subscribeObserver(view);
			
			addChild(view);
			
		}
		
	}
	
}